package com.shop.service.impl;

import com.shop.entity.UserBehavior;
import com.shop.mapper.UserBehaviorMapper;
import com.shop.service.UserBehaviorService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author XCH
 * @date 2025 - 06 - 24
 */
@Service("userBehaviorService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class UserBehaviorServiceImpl implements UserBehaviorService {
    private final UserBehaviorMapper userBehaviorMapper;
    @Override
    public List<UserBehavior> getUserBehaviorByUserId(Integer userId) {
        if (userId == null) {
            System.out.println("userId为空");
            return null;
        }
        return userBehaviorMapper.getUserBehaviorByUserId(userId);
    }

    @Override
    public List<UserBehavior> getProductIdAndActionType(Integer ProductId, Integer userId) {
        if (ProductId == null) {
            System.out.println("ProductId为空");
            return null;
        }
        return userBehaviorMapper.getProductIdAndActionType(ProductId, userId);
    }

    @Override
    public void addUserBehavior(int userId, int productId, String actionType, String createTime) {
        userBehaviorMapper.addUserBehavior(userId, productId, actionType, createTime);
    }

    @Override
    public void deleteUserBehavior(Integer id) {
        userBehaviorMapper.deleteUserBehavior(id);
    }

    @Override
    public void updateUserBehaviorByCreateTime(LocalDateTime createTime, Integer id) {
        userBehaviorMapper.updateUserBehaviorByCreateTime(createTime, id);
    }
}
